﻿using DirectCanvas;
using DirectCanvas.Effects;
using DirectCanvas.Misc;

namespace WindowsFormsTest.Demos.EffectsDemo
{
    public class RippleSettings
    {
        public PointF Center { get; set; }
        public float Amplitude { get; set; }
        public float Frequency { get; set; }
        public float LightIntensity { get; set; }
        public float Phase { get; set; }

        public RippleSettings()
        {
            this.Amplitude = 0.02f;
            this.Frequency = 80;
            this.LightIntensity = 0.8f;
            this.Phase = 0;
            this.Center = new PointF(0.5f, 0.5f);
        }

        public void Update()
        {
            this.Phase -= 0.2f;

            this.Frequency -= 0.5f;
            if (this.Frequency < 5)
                this.Frequency = 5;

            this.Amplitude -= 0.0001f;
            if (this.Amplitude < 0.001f)
                this.Amplitude = 0.001f;
            
            this.LightIntensity -= 0.005f;
            if (this.LightIntensity < 0.02f)
                this.LightIntensity = 0.02f;
        }

        public void Apply(RippleEffect effect, DrawingLayer sourceLayer, DrawingLayer targetLayer)
        {
            effect.Center = Center;
            effect.Amplitude = Amplitude;
            effect.Frequency = Frequency;
            effect.LightIntensity = LightIntensity;
            effect.Phase = Phase;

            sourceLayer.ApplyEffect(effect, targetLayer);
        }
    }
}